// MusicPack.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Linq;

using Supremacy.Annotations;
using Supremacy.Resources;

namespace Supremacy.Client
{
    [Serializable]
    public class MusicTrack
    {
        private readonly string _trackName;
        private readonly string _fileName;

        public MusicTrack([NotNull] string trackName, [NotNull] string fileName)
        {
            if (trackName == null)
                throw new ArgumentNullException("trackName");
            if (fileName == null)
                throw new ArgumentNullException("fileName");
            _trackName = trackName;
            _fileName = fileName;
        }

        public string FileName
        {
            get { return _fileName; }
        }

        public string TrackName
        {
            get { return _trackName; }
        }
    }

    [Serializable]
    public class MusicPack
    {
        public ReadOnlyCollection<MusicTrack> Tracks { get; private set; }

        public static MusicPack LoadDefault()
        {
            var xmlDoc = XDocument.Load(ResourceManager.GetResourcePath("Resources/Data/MusicPacks.xml"));
            var tracks = from trackElement in xmlDoc.Descendants("DefaultMusicPack").Elements()
                         let fileName = trackElement.Value.Trim()
                         where !string.IsNullOrEmpty(fileName)
                         select new MusicTrack(trackElement.Name.LocalName, fileName);
            return new MusicPack { Tracks = tracks.ToList().AsReadOnly() };}
    }
}
